import 'package:dart_sdk/dio_util.dart';
import 'package:dio/dio.dart';

class GateWayDio {
  static Future<String> createNewChannel(String identity) async {
    Map<String, dynamic> result = await HoxinUtil.httpPost(
        "/CreateNewChannel", FormData.fromMap({"identity": identity}));
    return result['data'] as String;
  }

  static Future<bool> deleteChannel(String channelid) async {
    Map<String, dynamic> result =
        await HoxinUtil.httpDelete("/DeleteChannel?channelid=$channelid", null);
    return result["message"] == "success";
  }

  static Future<int> getChannelConnCount(String channelid) async {
    Map<String, dynamic> result = await HoxinUtil.httpGet(
        "/GetChannelConnCount?channelid=$channelid", null);
    return result['data'] as int;
  }

  static Future<bool> deleteChannelMember(
      String channelid, String identity) async {
    Map<String, dynamic> result = await HoxinUtil.httpDelete(
        "/DeleteChannelMember",
        FormData.fromMap({"channelid": channelid, "identity": identity}));
    return result["message"] == "success";
  }

  static Future<bool> unsubscribleChannel(
      String channelid, String identity) async {
    Map<String, dynamic> result = await HoxinUtil.httpDelete(
        "/UnSubscribleChannel",
        FormData.fromMap({"channelid": channelid, "identity": identity}));
    return result["message"] == "success";
  }

  static Future<Map<String, dynamic>> publishToChannel(
      String channel, String sender, String data) async {
    Map<String, dynamic> result = await HoxinUtil.httpPost("/PublishToChannel",
        FormData.fromMap({"channel": channel, "sender": sender, "data": data}));
    return result;
  }
}
